<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Server-side Pagination</title>

<style type="text/css">
/*margin and padding on body element
  can introduce errors in determining
  element position and are not recommended;
  we turn them off as a foundation for YUI
  CSS treatments. */
body {
	margin:0;
	padding:0;
}
</style>

<link rel="stylesheet" type="text/css" href="../../build/fonts/fonts-min.css" />
<link rel="stylesheet" type="text/css" href="../../build/datatable/assets/skins/sam/datatable.css" />
<script type="text/javascript" src="../../build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="../../build/connection/connection-min.js"></script>
<script type="text/javascript" src="../../build/json/json-min.js"></script>
<script type="text/javascript" src="../../build/element/element-beta-min.js"></script>
<script type="text/javascript" src="../../build/datasource/datasource-beta-min.js"></script>
<script type="text/javascript" src="../../build/datatable/datatable-beta-min.js"></script>


<!--begin custom header content for this example-->
<style type="text/css">
    #paging a {
        color: #0000de;
    }
</style>

<!--end custom header content for this example-->

</head>

<body class=" yui-skin-sam">

<h1>Server-side Pagination</h1>

<div class="exampleIntro">
	<p>This example illustrates how to configure a DataTable instance to page through a large data set managed on the server.</p>
			
</div>

<!--BEGIN SOURCE CODE FOR EXAMPLE =============================== -->

<div id="demo">
    <div id="paging"></div>
    <div id="dt"></div>
</div>
<script type="text/javascript">
YAHOO.util.Event.onDOMReady(function () {
    var DataSource = YAHOO.util.DataSource,
        DataTable  = YAHOO.widget.DataTable,
        Paginator  = YAHOO.widget.Paginator;

    var mySource = new DataSource('assets/php/json_proxy.php?');
    mySource.responseType   = DataSource.TYPE_JSON;
    mySource.responseSchema = {
        resultsList : 'records',
        fields      : [
            'id','name','date','price','number','address','company',
            'desc','age','title','phone','email','zip','country'],
        metaFields : {
            totalRecords: 'totalRecords' // The totalRecords meta field is
                                         // a "magic" meta, and will be passed
                                         // to the Paginator.
        }
    };

    var buildQueryString = function (state,dt) {
        return "startIndex=" + state.pagination.recordOffset +
               "&results=" + state.pagination.rowsPerPage;
    };

    var myPaginator = new Paginator({
        containers         : ['paging'],
        pageLinks          : 5,
        rowsPerPage        : 15,
        rowsPerPageOptions : [15,30,60],
        template           : "<strong>{CurrentPageReport}</strong> {PreviousPageLink} {PageLinks} {NextPageLink} {RowsPerPageDropdown}"
    });

    var myTableConfig = {
        initialRequest         : 'startIndex=0&results=25',
        generateRequest        : buildQueryString,
        paginationEventHandler : DataTable.handleDataSourcePagination,
        paginator              : myPaginator
    };

    var myColumnDefs = [
        {key:"id"},
        {key:"date"},
        {key:"price"},
        {key:"age"},
        {key:"desc"}
    ];

    var myTable = new DataTable('dt', myColumnDefs, mySource, myTableConfig);
});
</script>

<!--END SOURCE CODE FOR EXAMPLE =============================== -->

</body>
</html>